package com.study.dao.impl;

import com.study.dao.BookDao;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import java.util.List;

/**
 * @author WS
 */
public class BookDaoImpl extends HibernateDaoSupport implements BookDao {
    //查询图书信息
    @Override
    public Book selectBook(String ISBN) {
        List list = this.getHibernateTemplate().find("from Book where ISBN=?", ISBN);
        Book book = null;
        if (list.size() > 0) {
            book = (Book) list.get(0);
        }
        return book;
    }

    //添加图书信息
    @Override
    public void addBook(Book book) {
        this.getHibernateTemplate().save(book);
    }

    //删除图书信息
    @Override
    public void deleteBook(String ISBN) {
        this.getHibernateTemplate().delete(this.selectBook(ISBN));
    }

    //修改图书信息
    @Override
    public void updateBook(Book book) {
        this.getHibernateTemplate().update(book);
    }
}

